package com.example.Administrator.shoujiweishi.fragments;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;


import com.example.Administrator.shoujiweishi.R;
import com.example.Administrator.shoujiweishi.fragments.base.BaseDialogFragment;
import com.example.Administrator.shoujiweishi.services.MyDownLoadService;
import com.example.Administrator.shoujiweishi.vo.VersionInfo;

import butterknife.Unbinder;

/**
 * Created by Administrator on 2017/4/20.
 */

public class UpdataVersionDialogFragment extends BaseDialogFragment implements View.OnClickListener {
    private TextView textDailogfragment;
    private Button button_jujue;
    private Button button_queding;
    Unbinder unbinder;
    public String str;

    @Override
    public int getContentXml() {
        return R.layout.updata_version_dialogfragment;
    }

    @Override
    public void initDataView(View view) {
        textDailogfragment= (TextView) view.findViewById(R.id.text_dailogfragment);
        button_jujue= (Button) view.findViewById(R.id.but_no);
        button_queding= (Button) view.findViewById(R.id.but_yes);
        button_jujue.setOnClickListener(this);
        button_queding.setOnClickListener(this);
        Bundle bundle=getArguments();
        VersionInfo versionInfo= (VersionInfo) bundle.get("versionInfo");
        if(versionInfo!=null){
            textDailogfragment.setText(versionInfo.getInfo());
        }else {
            button_jujue.setVisibility(View.GONE);
            textDailogfragment.setText(bundle.getString("Info"));
        }
    }

    public static UpdataVersionDialogFragment getUpdateDialogFragment(VersionInfo versionInfo){
        Bundle bundle=new Bundle();
        bundle.putSerializable("versionInfo",versionInfo);
        UpdataVersionDialogFragment updataVersionDialogFragment=new UpdataVersionDialogFragment();
        updataVersionDialogFragment.setArguments(bundle);
        return updataVersionDialogFragment;
    }
    public static UpdataVersionDialogFragment getUpdateDialogFragment(String s){
        Bundle bundle=new Bundle();
        bundle.putString("Info",s);
        UpdataVersionDialogFragment updataVersionDialogFragment=new UpdataVersionDialogFragment();
        updataVersionDialogFragment.setArguments(bundle);
        return updataVersionDialogFragment;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.but_no:
                dismiss();
                break;
            case R.id.but_yes:
                Bundle bundle=getArguments();
                VersionInfo versionInfo= (VersionInfo) bundle.get("versionInfo");
                if(versionInfo!=null){
                    Intent intent=new Intent();
                    intent.setClass(getActivity(), MyDownLoadService.class);
                    intent.putExtra("apkUrl",versionInfo.getApkUrl());
                    getActivity().startService(intent);
                }
                dismiss();
                break;
        }
    }


}
